#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N=1000003;
int n;ll k;
bool vis[N];
int p[N];
ll a[N];
ll fac[23];
int stk[N];
int f[N];
void contor(int len){
	--k;
	for(int i=1;i<=len;++i){
		int cc=k%i;
		k/=i;
		f[i]=++cc;
		for(int j=1;j<i;++j)
			if(f[j]>=cc) ++f[j];
	}
	reverse(f+1,f+len+1);
}
void dfs(int x,int lim){
	if(x>n){
		--k;
		if(!k){
			for(int i=1;i<=n;++i) printf("%d ",p[i]);
			putchar('\n');
			exit(0);
		}
		return;
	}
	if(lim>n){
		if(n-x+1>20){
			int tp=0;
			for(int i=1;i<=n;++i) if(!vis[i]) stk[++tp]=i;
			for(int i=1;i<x;++i) printf("%d ",p[i]);
			for(int i=x;i<=n-20;++i) printf("%d ",stk[i-x+1]);
			contor(20);
			for(int i=1;i<=20;++i) printf("%d ",stk[tp-20+f[i]]);
			putchar('\n');
			exit(0);
		}
		if(fac[n-x+1]>=k){
			int tp=0;
			for(int i=1;i<=n;++i) if(!vis[i]) stk[++tp]=i;
			for(int i=1;i<x;++i) printf("%d ",p[i]);
			contor(tp);
			for(int i=1;i<=tp;++i) printf("%d ",stk[f[i]]);
			putchar('\n');
			exit(0);
		}
		k-=fac[n-x+1];
		return;
	}
	for(int i=1;i<lim||(x==1&&i<=n);++i){
		if(vis[i]) continue;
		vis[i]=1;p[x]=i;
		dfs(x+1,lim+i);
		vis[i]=0;
	}
}
int main(){
	freopen("permutation.in","r",stdin);
	freopen("permutation.out","w",stdout);
	scanf("%d%lld",&n,&k);
	fac[0]=1;
	for(int i=1;i<=20;++i) fac[i]=fac[i-1]*i;
	dfs(1,0);
	return 0;
}
